package com.xpgk.mvc.statistic.dailyNursing;

import java.util.List;

import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.user.User;

public class DailyNursingStatisticController extends  BaseController{
	
	private  DailyNursingStatisticService  dailyNursingStatisticService;
	
	
	
	
	public  void  index(){	
		
		Organization  org=Organization.dao.findById(getCUserOrganIds());
		setAttr("organization", org);
		render("dailyNursingStatistic.html");
	}
	
	public void queryDaily(){
		Organization  org=Organization.dao.findById(getPara("organids"));
		setAttr("organization", org);
		render("/dlstasticinfo/dailyNursing.html");
	}
	
	
	/**获取日护理数据
	 * 
	 * @throws Exception
	 */
	public  void  getDailyNursingInfo() throws Exception{
		String  month=getPara("month");
		String  organIds=getPara("organIds");
		String  name=getPara("cusname");
		String  phone=getPara("cusphone");
		String  hybh=getPara("cushybh");
		String  fzUser=getPara("fzUser");
		String  arrivedMinTimes=getPara("arrivedMinTimes");
		String  arrivedMaxTimes=getPara("arrivedMaxTimes");
		
		List<Record>  dailyNursingList =dailyNursingStatisticService.getDailyNursingInfo(month,organIds,name,phone,hybh,fzUser,arrivedMinTimes, arrivedMaxTimes);
		renderJson(dailyNursingList);
	}
	/**导出
	 * @throws Exception 
	 * 
	 */
	public  void  excel() throws Exception
	{
		String  month=getPara("month");
		String  organIds=getPara("organIds");
		String  name=getPara("cusname");
		String  phone=getPara("cusphone");
		String  hybh=getPara("cushybh");
		String  fzUser=getPara("fzUser");
		String  arrivedMinTimes=getPara("arrivedMinTimes");
		String  arrivedMaxTimes=getPara("arrivedMaxTimes");
		
		 List<Record>  dailyNursingList =dailyNursingStatisticService.getDailyNursingInfo(month,organIds,name,phone,hybh,fzUser,arrivedMinTimes,
				 arrivedMaxTimes);
		 
		 //搜索条件
		 Organization  organ=Organization.dao.findById(organIds);
		 User  user=User.dao.findById(fzUser);
		 
		 String cusnamestr=name.equals("")?"":(",顾客姓名："+name);
		 String cusphonestr=phone.equals("")?"":(",顾客手机："+phone);
		 String cusbhstr=hybh.equals("")?"":(",顾客编号："+hybh);
		 String fzrstr=user==null?"":(",顾客负责人："+user.getStr(User.column_name));
		 String arrivedMinTimesstr=arrivedMinTimes.equals("")?"":(",最少到店次数："+arrivedMinTimes);
		 String arrivedMaxTimesstr=arrivedMaxTimes.equals("")?"":(",最多到点次数："+arrivedMaxTimes);
		 
		 String  search="日期："+month+",门店："+organ.getStr(Organization.column_name)+
				 cusnamestr+cusphonestr+cusbhstr+fzrstr+arrivedMinTimesstr+arrivedMaxTimesstr+",导出人员："+getCUser().getStr(User.column_name);
		 
		 render(new DailyNursingStatisticXLS(dailyNursingList,search,"日护理表"));
	}
}
